package service.Impl;

import com.alibaba.fastjson.JSON;
import controller.wechat.WechatAcceptToken;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import util.api.ApIURL;
import util.httpclient.HttpService;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by thinkjoy on 2017/9/6.
 */
@Service
public class WsToken {

    @Autowired
    private HttpService httpService;

    public void getToken(){
        Map<String,Object> value=new HashMap<>();
        value.put("grant_type","client_credential");
        value.put("appid", ApIURL.APPID);
        value.put("secret",ApIURL.APPSECRET);
        try {
            String result=httpService.doGet(ApIURL.TOKEN_URL,value);
            ApIURL.ACCESS_TOKEN= JSON.parseObject(result).getString("access_token");
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
